<style>
    body {
        background-color: #ffffff;
    }
</style>
<div class="layui-form layuimini-form">
    <div class="layui-form-item">
        <label class="layui-form-label required">分类名</label>
        <div class="layui-input-block">
            <input type="text" name="name" lay-verify="required" lay-reqtext="分类名不能为空" placeholder="请输入分类名" value="{{.info.Name}}"
                   class="layui-input">
            <input type="hidden" name="type" value="0">
            <input type="hidden" name="id" value="{{.info.Id}}">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>
<script>
    layui.use(['form'], function () {
        let form = layui.form,
            layer = layui.layer,
            $ = layui.$;

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            let load;
            $.ajax({
                url: '/admin/api/category/edit',
                type: "POST",
                data: data.field,
                dataType: "json",
                beforeSend: function () {
                    load = layer.load(2);
                },
                complete: function () {
                    layer.close(load)
                },
                success: function (data) {
                    if (data.code === 1) {
                        // 关闭弹出层
                        layer.msg(data.message, {icon: 1, title: "success"}, function () {
                            let iframeIndex = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(iframeIndex);
                        });
                    } else {
                        layer.msg(data.message, {icon: 2, title: "error"})
                    }
                }
            });

            return false;
        });

    });
</script>